/*
 *  Copyright 2010 netjois.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package edu.upf.userinterface.impl;

import edu.upf.content.DescriptionContent;
import edu.upf.utils.Definitions;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author netjois
 */
public class LibraryTableModel extends AbstractTableModel implements Definitions {

    private List<DescriptionContent> datalist = new ArrayList();
    int columns;

    public LibraryTableModel(){
        columns=0;
    }

    public void setColumns(int columns){
        this.columns=columns;
        fireTableStructureChanged();
    }

    @Override
    public int getRowCount() {
        return (int) Math.ceil((double)datalist.size()/(double)columns);
    }

    @Override
    public int getColumnCount() {
        return columns;
    }

    @Override
    public String getColumnName(int col) {
        return null;
    }

    public void setContent(List content){
        datalist=content;
        fireTableDataChanged();
    }

    public DescriptionContent getContentAt(int row, int col){
        int pos=columns*row+col;
        return datalist.get(pos);
    }

    @Override
    public Class getColumnClass(int column){
        return Image.class;
    }

    @Override
    public Object getValueAt(int row, int col) {
        int pos=columns*row+col;
        if(pos>=datalist.size()){
            return null;
        }else{
           return datalist.get(columns*row+col).getThumbnail();
        }
        
    }
}
